<?php get_header(); ?>

<?php get_sidebar(); ?>

<?php 
// get portfolio category info
$term=get_term_by('slug',get_query_var( 'term' ),get_query_var('taxonomy'));
// get portfolio category template
$template=bandit::get_option('theme_portfolio_'.$term->slug);
$template=$template?$template:'1';
// get portfolio category num
$template_num=bandit::get_option('theme_portfolio_'.$term->slug.'_num');
$template_num=$template_num?$template_num:'-1';
// get ajax nav option
$ajaxnav=bandit::get_option('theme_portfolio_ajaxnav');
// portfolio loop
$args=array('post_type'=>'portfolio','portfolio_category'=>$term->slug,
	'posts_per_page'=>$template_num);
if('-1'!=$template_num) {
	$paged=get_query_var('page')?get_query_var('page'):1;
	$args['posts_per_page']=$template_num;
	$args['paged']=$paged;
}
$loop=new WP_Query($args);

function ieversion() {
  $match=preg_match('/MSIE ([0-9]\.[0-9])/',$_SERVER['HTTP_USER_AGENT'],$reg);
  if($match==0)
    return false;
  else
    return floatval($reg[1]);
}
$ie=(ieversion())?ieversion():10;
?>

<div id="right" class="t-portfolio">

	<header id="header">
		<div id="header-inner">
			<h2><?php bandit::lang('heading_portfolio',__('Portfolio','creatic')); ?></h2>
			<ul id="button-menu" class="clearfix">
				<?php wp_list_categories(array('taxonomy'=>'portfolio_category','orderby'=>'name','title_li'=>'')); ?>
			</ul>
		</div><!--end header-inner-->
	</header><!--end header-->
	
	<div id="content">
		<div id="content-inner">
			<div id="content-pad">
			
				<?php if ($term->description): ?>
					<section class="description">
						<p><?php echo $term->description; ?></p>
					</section>
				<?php endif; ?>
				<div id="masonry">
					<?php require(get_template_directory().'/templates/portfolio-'.$template.'.php'); ?>
				</div><!--end masonry-->

				<div class="clear"></div>
			</div><!--end content-pad-->
			
			<?php if(bandit::get_option('theme_portfolio_rewrite_category')!='') { $pagevar='?page='; } else { $pagevar='&page='; } ?>

				<?php if($ajaxnav && $loop->max_num_pages>1 && 1==$paged && ($ie > 8)): ?>
				<!--ajax nav-->
				<nav class="entry-nav clearfix">
					<p><a id="entry-load-more-link" data-empty="No more items available." data-max="<?php echo $loop->max_num_pages; ?>" data-src="<?php echo get_term_link($term).$pagevar; ?>" href="#"><?php bandit::lang('post_nav_ajax',__('Load More','creatic')); ?></a></p>
				</nav>
				<!--end ajax nav-->
				<?php endif; ?>


				<?php if((!$ajaxnav && $loop->max_num_pages>1) || (1!=$paged && '0'!=$template_num) || ($ie < 9)): ?>
				<!--standard nav-->
				<nav class="entry-nav clearfix">
					<ul>
				<?php if ($paged > 1): ?>
				<?php $page_link=(($paged-1)!=1)?$pagevar.($paged-1):''; ?>
						<li class="prev left"><a href="<?php echo get_term_link($term).$page_link; ?>"><?php bandit::lang('post_nav_prev',__('&larr; Previous','creatic')); ?></a></li>
				<?php endif; ?>

				<?php if($paged < $loop->max_num_pages): ?>
						<li class="next right"><a href="<?php echo get_term_link($term).$pagevar.($paged+1); ?>"><?php bandit::lang('post_nav_next',__('Next &rarr;','creatic')); ?></a></li>
				<?php endif; ?>
					</ul>
				</nav>
				<!--end standard nav-->
			
			<?php endif; ?>
			<?php if(bandit::get_option('footer_widgets_portfolio')) { get_template_part('footer-widgets'); } // footer-widgets.php ?>
		</div><!--end content-inner-->
		<div class="clear"></div>
	</div><!--end content-->

</div><!--end right-->

<?php get_footer(); ?>